package leo.game.ui
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import leo.TDGame;
	import leo.data.Config;
	import leo.data.GameConfig;
	import leo.data.GameConst;
	import leo.game.stage.BaseStage;

	/**
	 * 小loading界面 
	 * @author leo
	 * 
	 */	
	public class UIInitLoading extends BaseStage
	{
		/**
		 * 小loading 
		 */		
		private var smallLoadingMC :MovieClip;
		/**
		 * 加载器 
		 */		
		private var loader :Loader;
		/**
		 * 大loading 
		 */		
		private var bigLoadingMC :UIMainLoading;
		public function UIInitLoading()
		{
			super();
			init();
		}
		
		private function init():void
		{
			smallLoadingMC = new MC_InitLoading();
			smallLoadingMC.x = TDGame.instance.stage.stageWidth/2;
			smallLoadingMC.y = TDGame.instance.stage.stageHeight/2;
			addChild(smallLoadingMC);
			
			new Config(load);
		}
		
		private function load():void
		{
			loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
			var loaderContext :LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);
			loader.load(new URLRequest(GameConfig.big_loading_url),loaderContext);
		}
		
		private function loaderHandler(event :Event):void
		{
			if(smallLoadingMC)
			{
				if(smallLoadingMC.parent)
				{
					smallLoadingMC.parent.removeChild(smallLoadingMC);
					smallLoadingMC = null;
				}
			}
			var evt :EventDispatcher = event.currentTarget as EventDispatcher;
			evt.removeEventListener(Event.COMPLETE,loaderHandler);
			
			addChild(UIMainLoading.instance);
		}
	}
}